<template>
  <div>
    <!-- 搜索 -->
    <!-- 预授权级别维护 -->
    <TopFilter ref="topFilter" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="120" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable ref="table" :columns="columns" :params="fetchParams" :fetchapi="fetchapi" :datakey="'records'" :onColumnsChange="columns => (this.columns = columns)" :onRowSelectChange="selectChange" :is-select-column="false" :isPagination="isPagination">
    </FilterTable>
    <BaseDialog width="30%" :visible.sync="visibleEdit" :title="dialogTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 70px)', overflow: 'auto', paddingBottom: '70px' }">
      <editForm :row="rowData" @close="closeDialog" />
    </BaseDialog>
  </div>
</template>

<script>
import { getListByPage } from '@/api/claim/dealer/AuthMaintenance';
import { factoryEmployeeSearch } from '@/api/common/auth/dealerStaff';
import editForm from './editForm.vue';
import { getAppId } from '@/assets/js/auth';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: "index",
  mixins: [dictionary],
  components: {
    editForm
  },
  data() {
    return {
      isPagination: false,
      topFilterInit: this.topFilterInitFun(),
      fetchParams: { xhrAbort: false }, //ipa 接口
      columns: this.creatHeader(),
      selectedRows: [], //选中
      collapse: true,
      fetchapi: getListByPage,
      visibleEdit: false,
      rowData: {},
      dialogTitle: '',
    }
  },
  created() {
  },
  methods: {
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '预授权级别编号', fieldName: 'code', placeholder: '请输入预授权级别编号...', initialValue: '' },
        { type: 'INPUT', label: '预授权级别名称', fieldName: 'name', placeholder: '请输入预授权级别名称...', initialValue: '' },
        { type: 'SELECT', label: '预授权类型', fieldName: 'authType', placeholder: '请选择预授权类型...', itemList: this.createDictList('5508'), initialValue: '' },
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val, { xhrAbort: false });
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '预授权级别编号', dataIndex: 'code', sorter: true },
        { title: '预授权级别名称', dataIndex: 'name', sorter: true },
        {
          title: '预授权类型', dataIndex: 'authType',
          filterItems: this.createDictList('5508'),
          dictItems: this.createDictList('5508'),
          render: props => {
            return <span>{this.createDictText(props.row.authType, '5508')}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          render: props => {
            return (
              <div style="text-align:center">
                <multiuse-button size="mini" type="text" onClick={() => this.edit(props.row)} >
                  编辑 </multiuse-button>
              </div>
            );
          }
        },
      ];
    },
    //选中行
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    editclose() {
      this.visibleEdit = false;
    },
    edit(val) {
      this.rowData = val;
      this.visibleEdit = true;
      this.dialogTitle = '预授权编辑';
    },
    async closeDialog() {
      // this.action.visible = false;
      this.visibleEdit = false;
      const [err, data] = await this.$refs.topFilter.GET_FORM_DATA();
      this.fetchParams = { ...this.fetchParams, ...data };
    }
  }
}
</script>

<style scoped>
</style>
